#ifndef __ANONYMITY_H_
#define __ANONYMITY_H_
#include <stdint.h>

/**
 *  nonymity frame format
 *  --------------------------------------------------------------
 *  name  | HEAD | S_ADDR | ID | LEN | DATA | SUM_CHK | ADD_CHK |
 *  -------------------------------------------------------------- 
 *  bytes |   1  |   1    |  1 |  2  |  N   |    1    |    1    |
 *  --------------------------------------------------------------
 *  */

typedef struct {

    uint8_t head;
    uint8_t s_addr;
    uint8_t d_addr;
    uint8_t id;
    uint16_t length;
} __attribute__((packed)) anonymity_header_t;


/// @brief anonymous protocol frame data packaging
/// @param pack_buf the address where the data is packaged and stored
/// @param pack_max_length maximum length of data packaging
/// @param header data headers
/// @param data data content address
/// @param length data content length
/// @return 
int32_t anonymity_frame_pack(uint8_t *pack_buf, uint32_t pack_max_length, anonymity_header_t *header, uint8_t *data, uint32_t length);

/// @brief unwrapping of the anonymous protocol
/// @param source_buff original packet
/// @param length the length of the data
/// @param header data headers
/// @param data data content address
/// @param max_length data content max length
/// @return 
int32_t anonymity_frame_unpack(uint8_t *source_buff, uint32_t length,
                             anonymity_header_t *header, uint8_t *data, uint16_t max_length);

#endif // __ANONYMITY_H_

